package com.xing.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xing.dto.LiveRoomDTO;
import com.xing.entity.LiveRoomEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LiveRoomDao extends BaseMapper<LiveRoomEntity> {

    @Select("select lr.id,\n" +
            "       lr.anchor_id,\n" +
            "       lr.room_number,\n" +
            "       lr.info,\n" +
            "       so.url,\n" +
            "       lr.notice,\n" +
            "       lr.broadcast_flag,\n" +
            "       lr.status,\n" +
            "       GROUP_CONCAT(lt.name) as tags\n" +
            "from live_room lr\n" +
            "         left join (select * from sys_oss where del_flag = 0) so on lr.cover_id = so.id\n" +
            "         left join live_room_tag lrt on lrt.room_id = lr.id\n" +
            "         left join live_tag lt on lrt.tag_id = lt.id\n" +
            "     where lr.del_flag = 0\n" +
            "     group by lr.id\n" +
            "limit #{pageStart},#{pageSize};")
    @ResultType(LiveRoomDTO.class)
    List<LiveRoomDTO> getLiveRoomByPage(@Param("pageStart") Integer pageStart, @Param("pageSize") Integer pageSize);
}
